/*
 * @Author: lizb
 */

_Pragma("once");

#include "WorkThread.h"

template<class WORKABLE>
class Workable
{
public:
    typedef WorkThread<WORKABLE> WorkableWorkThread;
    Workable();
    virtual ~Workable();

    WorkableWorkThread& getWorkThread()
    {
        if (NULL == mpWorkThread)
        {
            mpWorkThread = new WorkableWorkThread();
            mpWorkThread->setWorkable((typename  WorkableWorkThread::Workable*) this);
        }
        return *mpWorkThread;
    }

    /*  // must implements these function, for it work better, do not be virtual.
         bool initial();
         bool uninitial();

         bool doWork();
    */

private:
    WorkableWorkThread* mpWorkThread;
};


template<class WORKER>
Workable<WORKER>::Workable() : mpWorkThread(NULL)
{
}


template<class WORKER>
Workable<WORKER>::~Workable()
{
    if (NULL != mpWorkThread)
    {
        delete mpWorkThread;
        mpWorkThread = NULL;
    }
}

